{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Testing _check_relevance_with_conversation Function\n",
    "\n",
    "This notebook demonstrates how to use and test the `_check_relevance_with_conversation` function from the `doc_filter.py` module."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-12-19 22:37:37.731\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-12-19 22:37:37,801\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-12-19 22:37:37,832\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "\n",
    "# Initialize ByzerLLM\n",
    "llm = byzerllm.ByzerLLM.from_default_model(\"deepseek_chat\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create Sample Data\n",
    "\n",
    "Let's create some sample conversations and documents to test the relevance checking."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Sample conversation\n",
    "conversations = [\n",
    "    {\"role\": \"user\", \"content\": \"How do I use the ByzerLLM API?\"},\n",
    "    {\"role\": \"assistant\", \"content\": \"ByzerLLM provides a simple API for interacting with language models.\"},\n",
    "    {\"role\": \"user\", \"content\": \"Can you show me how to deploy a model?\"}\n",
    "]\n",
    "\n",
    "# Sample document\n",
    "document = \"\"\"\n",
    "# Deploying Models with ByzerLLM\n",
    "\n",
    "To deploy a model using ByzerLLM, follow these steps:\n",
    "\n",
    "1. Initialize the client\n",
    "2. Configure model parameters\n",
    "3. Deploy the model\n",
    "\n",
    "Example:\n",
    "```python\n",
    "import byzerllm\n",
    "llm = byzerllm.ByzerLLM()\n",
    "llm.deploy_model('my_model')\n",
    "```\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Initialize DocFilter and Test Relevance\n",
    "\n",
    "Now we'll create a DocFilter instance and test the relevance checking."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Relevance Result:\n",
      "yes/10\n"
     ]
    }
   ],
   "source": [
    "from autocoder.common import AutoCoderArgs\n",
    "from autocoder.rag.doc_filter import _check_relevance_with_conversation\n",
    "\n",
    "# Test relevance checking\n",
    "relevance = _check_relevance_with_conversation.with_llm(llm).run(conversations, [document])\n",
    "print(f\"Relevance Result:\\n{relevance}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
